using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Reflection;

namespace HelperMachine
{
    public static class Converters
    {
        public static Color ColorFromInt4(int[] i)
        {
            return new Color(i[0], i[1], i[2], i[3]);
        }

        public static Color ColorFromInt3(int[] i)
        {
            return new Color(i[0], i[1], i[2]);
        }

        public static Rectangle RectFromBRect(BasicParts.Rectangle r)
        {
            return new Rectangle(r.X, r.Y, r.Width, r.Height);
        }

        public static Vector2 Vector2FromInt2(int[] i)
        {
            return new Vector2(i[0], i[1]);
        }

        public static Vector2 Vector2FromFloat2(float[] f)
        {
            return new Vector2(f[0], f[1]);
        }

        public static List<string> GetEnumNames(this Enum enumType)
        {
            List<string> names = new List<string>();
            foreach (FieldInfo fi in enumType.GetType().GetFields(BindingFlags.Public | BindingFlags.Static))
                names.Add(fi.Name);
            return names;
        }

        public static bool EnumTryParse<T>(string value, out T parsedEnum)
        {
            try
            {
                parsedEnum = (T)Enum.Parse(typeof(T), value, true);
            }
            catch
            {
                parsedEnum = default(T);
                return false;
            }
            return true;
        }
    }
}